package cn.kill.orderservice.controller;

import cn.kill.orderservice.pojo.User;
import cn.kill.orderservice.service.user.UserService;
import cn.kill.orderservice.utils.Result;
import cn.kill.orderservice.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;

/**
 * 登录控制器
 * 
 * @author wangfan
 * @date 2017-3-24 下午3:56:37
 */
@RestController
@RequestMapping("/api")
public class LoginController{

	@Autowired
	private UserService userService;
	/**
	 * 登录
	 */
	@PostMapping("/login")
	public Result login(User user) throws Exception {
		if (StringUtil.isBlank(user.getUsername(), user.getPassword())) {
			return new Result(406, "请输入必填项！");
		}
		User loginUser = userService.getUserByUsername(user);
		if (loginUser == null) {
			return new Result(400, "用户不存在");
		}
//		if (loginUser.getState() == 0) {
//			return new Result(400, "用户禁用，请联系管理员");
//		}
//		String encryPsw = EndecryptUtils.encrytMd5(user.getPwd(), Salt.SALT, 3);
//		if (!loginUser.getPwd().equals(encryPsw)) {
//			return new Result(400, "密码错误");
//		}
//		String token = SubjectUtil.getInstance().createToken(loginUser.getId().toString(), DateUtil.getAppointDate(new Date(), 30));
//		loginUser.setPwd(null);
//		loginUser.setToken(token);
		return new Result(200, "登录成功",1);
	}


}